
import { _decorator, Component, Node, CCInteger, Vec3, math } from 'cc';
import { BuilderControl } from './BuilderControl';
import { SpawnItem, SpawnItemData } from './SpawnConfig';
const { ccclass, property } = _decorator;

@ccclass('FishControl')
export class FishControl extends BuilderControl {

    @property(CCInteger)
    gap = 0;
    x_pos = 0;

    //生成间隔


    //重载生成方法 
    createToEnd() {

        this.GetEndPos();

        // 
        let x = math.randomRangeInt(0, 3);
        if (x == 0) {
            this.x_pos = 0;
        } else if (x == 1) {
            this.x_pos = 1.25;
        } else if (x == 2) {
            this.x_pos = -1.25;
        }

        while (this.startCreatePosZ < this.endPosZ) {
            //每三个为一组 是纵向生成3个
            for (let i = 0; i < 3; i++) {
                let spawnItem = this.doSpawnItem();
                //三个生成完了 更新 this.startCreatePosZ
                if (spawnItem) {
                    this.startCreatePosZ += spawnItem.spawnItemData.node_length;
                }
            }

            this.startCreatePosZ += this.gap;


        }

    }



    onSpawn(node: Node, spawnItemData: SpawnItemData,) {

        node.setPosition(new Vec3(this.x_pos, 0.41, this.startCreatePosZ));
        node.active = true;

        // let newSpawnItem = new SpawnItem();

        // newSpawnItem.node = node;
        // newSpawnItem.spawnItemData = spawnItemData;
        // this.recoveryItemArr.push(newSpawnItem);
    }
}
